package ar.com.tallerdos.smartdinner.sync;

import android.os.AsyncTask;
import ar.com.tallerdos.smartdinner.activity.ComidaActivity;
import ar.com.tallerdos.smartdinner.model.Pedido;

public class NotificadorPlatos extends AsyncTask<Void, Void, Void> {
	
	private int actualizar = 0;
	private ComidaActivity activity;
		
	public NotificadorPlatos(ComidaActivity mainActivity) {
		activity = mainActivity;
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
	}

	@Override
	protected Void doInBackground(Void... params) {
		
		if(activity.getComida()!= null){
			actualizar = 0;
			for (Pedido pedido : activity.getComida().getPedidos()) {
				if (pedido.getNotificacion() == 1) {
					actualizar = 1;
					break;
				}
			}
		}
		return null;

	}

	@Override
	protected void onPostExecute(Void result) {
		// this method will be running on UI thread
		super.onPostExecute(result);
		if(actualizar == 1){
			activity.getListAdapter().notifyDataSetChanged();
			actualizar = 0;
		}
	}
}
